import 'package:dio/dio.dart';
import 'package:private_journey/States.dart';

import 'DbService.dart';

class BackgroundImage {
  String url;

  BackgroundImage(this.url);
}

class BackgroundImageService {
  static Future<String> currentBackgroundImage() async {
    DbService dbService = DbService();
    var url = await dbService.getUserBackGroundImage();
    return url;
  }

  static Future<void> changeBackgroundImage(String url) async {
    userBackGroundImage.value = url;
    DbService dbService = DbService();
    await dbService.updateUserBackGroundImage(url);
  }

  static Future<List<BackgroundImage>> fetchImages() async {
    Dio dio = Dio();
    var res = await dio.get(
      'https://api.unsplash.com/photos/?client_id=Ao7AHedH379jPmvZZTAPdyn2iUU6nBibHiB625p1InA',
    );
    var list = <BackgroundImage>[];
    for (var x in res.data) {
      list.add(BackgroundImage(x['urls']['regular']));
    }
    return list;
  }
}
